package retrofitdemo.com.night.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.lzy.okgo.callback.StringCallback;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import okhttp3.Call;
import okhttp3.Response;
import retrofitdemo.com.night.R;
import retrofitdemo.com.night.adapter.BWGClassAdapter;
import retrofitdemo.com.night.adapter.FloorMoreImageAdapter;
import retrofitdemo.com.night.bean.BWGClassBean;
import retrofitdemo.com.night.bean.FloorMoreImageBean;
import retrofitdemo.com.night.databinding.ActivityBwgClassBinding;
import retrofitdemo.com.night.databinding.ActivityFloorMoreImageBinding;
import retrofitdemo.com.night.utils.GsonUtil;
import retrofitdemo.com.night.utils.HTTPAPI;
import retrofitdemo.com.night.utils.LogUtil;
import retrofitdemo.com.night.utils.OnItemClickListener;
import retrofitdemo.com.night.utils.TaoLinear;

/**
 * Created by 86178 on 2020/3/12.
 * author mogen
 * 用心，成就一切。
 */
public class BWGClassActivity extends BaseActivity{

    ActivityBwgClassBinding binding;
    BWGClassAdapter adapter;
    List<BWGClassBean.DataBean> listSecond = new ArrayList<>(  );
    List<BWGClassBean.DataBean> list = new ArrayList<>(  );
    BWGClassBean bean;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        binding = DataBindingUtil.setContentView( this, R.layout.activity_bwg_class );
        binding.setActivity( this );
        initView();
    }

    private void initView() {
        setTitleText( "博物馆活动" );
        setBack();

        binding.rlModule.setLayoutManager( new LinearLayoutManager( this ) );
        binding.rlModule.setItemAnimator( new DefaultItemAnimator() );
        adapter = new BWGClassAdapter( this,listSecond );
        binding.rlModule.setAdapter( adapter );
        adapter.setOnItemClickLitener( new OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {

            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        } );


        HTTPAPI.getInstance().getBWGClass(new StringCallback() {
            @Override
            public void onSuccess(String s, Call call, Response response) {
                LogUtil.e( "获取活动成功-->"+ s );
                try {
                    bean = GsonUtil.GsonToBean( s, BWGClassBean.class );
                    list.clear();
                    list = bean.getData();
                    listSecond.addAll( list );
                    adapter.notifyDataSetChanged();
                }catch (Exception e){

                }
            }
        });

    }


}
